package myNetty.action1;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author tonywang
 * @date 7/25/2018
 */
public class FutureExample {
    public static void main(String[] args){
        ExecutorService executor = Executors.newCachedThreadPool();
        Runnable task1 = new Runnable() {
            @Override
            public void run() {
                System.out.println("i am task1.....");
            }
        };
        Callable<Integer> task2 = new Callable<Integer>() {
            @Override
            public Integer call() throws Exception {
                return new Integer(100);
            }
        };
        Future<?> future1 = executor.submit(task1);
        Future<Integer> future2= executor.submit(task2);
        System.out.println("task1 is completed? " + future1.isDone());
        System.out.println("task2 is completed? " + future2.isDone());

        while (future1.isDone()){
            System.out.println("task1 completed.");
            break;
        }

        while (future2.isDone()){
            System.out.println("task2 completed.");
            break;
        }
    }
}
